package com.superitem.school.config;

import com.superitem.school.interceptor.MyInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import org.springframework.web.servlet.config.annotation.*;


@Configuration
public class MyConfig implements WebMvcConfigurer {

    //注册拦截器
    @Bean
    public MyInterceptor myInterceptor(){
        return new MyInterceptor();
    }

    //将拦截器添加到拦截器链，指定拦截规则
    @Override
    public void addInterceptors(InterceptorRegistry registry){
        registry.addInterceptor(myInterceptor()).addPathPatterns("/**")
                .excludePathPatterns("/student/**")
                .excludePathPatterns("/error/**")
                .excludePathPatterns("/user/**")
                .excludePathPatterns("/css/**")
                .excludePathPatterns("/goods/**")
                .excludePathPatterns("/tmp/**");
        //放行以及拦截的都是控制层RequestMapping中的url
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry){
        registry.addResourceHandler("/tmp/**").addResourceLocations("file:D:\\IDEA\\IDEAprojects\\SH_Work\\SpringBootltem\\target\\classes\\templates\\tmp\\");
    }
}
